package com.agile.leetcode.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2023/1/16 21:57
 */
public class ObjectToOtherUtil {
    public static <T> List<T> castList(Object obj, Class<T> clazz){
        List<T> result = new ArrayList<>();
        if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return null;
    }

    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("1");
        list.add("2");
        List<String> list1 = castList(list, String.class);
        System.out.println(list1);
    }
}
